<template>
  <!-- 布局管理 -->
  <div class="business-main">
    <!-- 状态选择框 -->
    <div class="topbar-view">
      <topBarButVue :isshowedit="false" @getstau="getstau" />
    </div>
    <!-- 业务组件展示表格 -->
    <div class="zh-table-view">
      <el-table :data="tableData" style="width: 100%" height="100%">
        <el-table-column type="index" width="50" />
        <el-table-column prop="layoutName" label="布局名称" width="180" />
        <el-table-column prop="layoutId" label="布局id" width="180" />
        <el-table-column prop="layoutCode" label="布局编码" width="180" />
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="mini" type="success" @click="showlineallmes(scope.$index, scope.row)">查看详情</el-button>
            <el-button size="mini" type="warning" @click="dellineallmes(scope.$index, scope.row)">删除</el-button>
            <el-button size="mini" type="primary" @click="editlineallmes(scope.$index, scope.row)">修改</el-button>
          </template>
        </el-table-column>
      </el-table>
      <Pagination :page-size="pageSize" :current-page="currentPage" :total-size="totalSize"
        @changePageSize="changePageSize" @changeCurrentPage="changeCurrentPage" />
    </div>
    <!-- 新增布局 -->
    <div v-if="diastau === 1" class="add-components-dia">
      <div class="top-bar"></div>
      <div class="top-title-line">
        <div class="line-title">新增一个布局组件</div>
        <div class="line-close" @click="setdiaview(0)">
          <i class="el-icon-close"></i>
        </div>
      </div>
      <div class="screen-dia-main">
        <!-- 标题配置 -->
        <div class="title-config">
          <div class="dia-main-inputline">
            <div class="inputline-name ">布局编码</div>
            <input v-model="addtitlrmes.layoutCode" class="inputline-value" />
          </div>
          <div class="dia-main-inputline">
            <div class="inputline-name">布局名称</div>
            <input v-model="addtitlrmes.layoutName" class="inputline-value" />
          </div>
        </div>
      </div>
      <div class="bottom-bar">
        <div class="bottom-bar-confirm" @click="savemes()">确认保存</div>
      </div>
    </div>
    <!-- 查看详细信息 -->
    <div v-if="diastau === 2" class="add-components-dia">
      <div class="top-bar"></div>
      <div class="top-title-line">
        <div class="line-title">业务组件详细信息</div>
        <div class="line-close" @click="setdiaview(0)">
          <i class="el-icon-close"></i>
        </div>
      </div>
      <div class="screen-dia-main">
        <!-- 标题配置 -->
        <div class="title-config">
          <div class="dia-main-inputline">
            <div class="inputline-name ">组件编码</div>
            <input v-model="contentmesage.layoutCode" class="inputline-value" />
          </div>
          <div class="dia-main-inputline">
            <div class="inputline-name">组件名称</div>
            <input v-model="contentmesage.layoutName" class="inputline-value" />
          </div>
        </div>
      </div>
    </div>
    <!-- 修改业务组件的弹框 -->
    <div v-if="diastau === 3" class="add-components-dia">
      <div class="top-bar"></div>
      <div class="top-title-line">
        <div class="line-title">业务组件修改</div>
        <div class="line-close" @click="setdiaview(0)">
          <i class="el-icon-close"></i>
        </div>
      </div>
      <div class="screen-dia-main">
        <!-- 标题配置 -->
        <div class="title-config">
          <div class="dia-main-inputline">
            <div class="inputline-name ">组件编码</div>
            <input v-model="editContentmesage.layoutCode" class="inputline-value" />
          </div>
          <div class="dia-main-inputline">
            <div class="inputline-name">组件名称</div>
            <input v-model="editContentmesage.layoutName" class="inputline-value" />
          </div>
        </div>
      </div>
      <div class="bottom-bar">
        <div class="bottom-bar-confirm" @click="savemesedit()">确认保存修改</div>
      </div>
    </div>
  </div>
</template>
<script>
import axios from 'axios';
import topBarButVue from '../components/top-bar-but.vue';
import Pagination from "@/components/Pagination";
export default {
  components: { topBarButVue, Pagination },
  data() {
    return {
      tableData: [],
      pageSize: 10,
      currentPage: 1,
      totalSize: 0,
      contentmesage: {
        "assemblyCode": "",
        "assemblyContentDTOList": [
          // {
          //   "dataSources": 0,
          //   "showType": "A1",
          //   "xAxis": 1,
          //   "yAxis": 1
          // }
        ],
        "assemblyEnName": "",
        "assemblyName": ""
      },
      editContentmesage: {
        "assemblyCode": "",
        "assemblyContentDTOList": [
          // {
          //   "dataSources": 0,
          //   "showType": "A1",
          //   "xAxis": 1,
          //   "yAxis": 1
          // }
        ],
        "assemblyEnName": "",
        "assemblyName": ""
      },
      // ---添加相关---
      diastau: 0,
      addtitlrmes: {
        assemblyName: "基地简介",
        assemblyEnName: "Base Des",
        assemblyCode: "nk1"
      },
      // 数据来源
      dataSourcesList: [
        { name: '动态数据', id: 0 },
        { name: '固定数据', id: 1 }
      ],
      selectStau: ''
    }
  },
  mounted() {
    this.gettabledataList()
  },
  methods: {
    // 获取表格信息
    gettabledataList() {
      let baseurl = this.$zhurl
      let requrl = baseurl + '/layout/queryPageList'
      axios({
        method: "GET",
        url: requrl,
        headers: {
          'Content-Type': "application/json;charset=UTF-8"
        },
        params: {
          page: this.currentPage,
          size: this.pageSize
        }
      }).then(response => {
        let mes = response.data
        if (mes.code === 1) {
          this.tableData = mes.data.list || []
          this.totalSize = mes.data.countNow
        } else {
          this.$message.warning("获取表格失败")
        }
      })
    },
    changePageSize(pageSize) {
      this.pageSize = pageSize;
      this.gettabledataList();
    },
    changeCurrentPage(currentPage) {
      this.currentPage = currentPage;
      this.gettabledataList();
    },
    // 查看详情
    showlineallmes(i, e) {
      this.contentmesage = e
      this.diastau = 2
    },
    // 删除一个布局
    dellineallmes(i, e) {
      this.$confirm('此操作将删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let baseurl = this.$zhurl
        let requrl = baseurl + '/layout/del'
        axios({
          method: "POST",
          url: requrl,
          headers: {
            'Content-Type': "application/json;charset=UTF-8"
          },
          data: {
            layoutId: e.layoutId
          }
        }).then(
          res => {
            if (res.data.code === 1) {
              this.$message.success("删除成功！")
              this.gettabledataList()
            }
          }
        )
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });

    },
    // 修改一个布局
    editlineallmes(i, e) {
      this.editContentmesage = e
      this.diastau = 3
    },
    // 保存要添加的业务的组件信息
    savemes() {
      let param = {
        layoutCode: this.addtitlrmes.layoutCode,
        layoutName: this.addtitlrmes.layoutName
      }
      let baseurl = this.$zhurl
      let requrl = baseurl + '/layout/add'
      axios({
        method: "POST",
        url: requrl,
        data: param
      }).then(response => {
        let mes = response.data
        if (mes.code === 1) {
          this.diastau = 0
          this.$message.success("添加成功！")
          this.gettabledataList()
        }
      })
    },
    // 修改时-保存要添加的业务的组件信息
    savemesedit() {
      let param = this.editContentmesage
      let baseurl = this.$zhurl
      let requrl = baseurl + '/layout/edit'
      axios({
        method: "POST",
        url: requrl,
        data: param
      }).then(response => {
        let mes = response.data
        if (mes.code === 1) {
          this.diastau = 0
          this.$message.success("修改成功！")
          this.gettabledataList()
        }
      })
    },
    // 获取状态
    getstau(e) {
      this.selectStau = e
      if (e === 'add') {
        this.diastau = 1
      } else if (e === 'complete') {
        this.diastau = 0
      } else if (e === 'edit') {
        // this.diastau = 3
      }
    },
    // 设置弹框展示
    setdiaview(i) {
      this.diastau = i
    }
  }
}
</script>

<style lang="scss" scoped>
@import "~@/styles/variables.scss";

.business-main {
  width: 100%;
  height: 100%;

  .topbar-view {
    width: 100%;
    margin-bottom: 5px;
  }

  .zh-table-view {
    width: 100%;
    height: calc(100% - 60px);
    position: relative;
  }
}

.add-components-dia {
  width: 482px;
  // height: 191px;
  background: #303640;
  border: 1px solid #005c6f;
  border-radius: 7px;
  position: fixed;
  top: 15%;
  left: 40%;
  // background-color: #005c6f;
  z-index: 99;

  .top-bar {
    width: 480px;
    height: 10px;
    background: linear-gradient(90deg, #3581fb 0%, #00faad 100%);
    border-radius: 7px 7px 0px 0px;
  }

  .top-title-line {
    width: 470px;
    height: 35px;
    line-height: 35px;
    padding: 6px 8px;
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid #484a4e;

    .line-title {
      height: 20px;
      font-size: 14px;
      font-family: PingFang SC-Regular, PingFang SC;
      font-weight: 400;
      color: $textColor;
      letter-spacing: 2px;
    }

    .line-close {
      color: #10d7c4;
      cursor: pointer;
    }

    .line-close:hover {
      color: $textColor;
    }
  }

  .screen-dia-main {
    width: 482px;
    padding: 20px 10px;
    // max-height: 550px;
    overflow-y: auto;
    overflow-x: hidden;
    max-height: 480px;

    .title-config {
      padding-bottom: 20px;
      border-bottom: #00faad 1px solid;
      margin-bottom: 10px;
    }

    .dia-main-inputline {
      width: 442px;
      margin-top: 5px;
      display: flex;
      justify-content: center;
      align-items: center;

      .inputline-name {
        width: 90px;
        height: 24px;
        font-size: 16px;
        font-family: PingFang SC-Regular, PingFang SC;
        font-weight: 400;
        color: $textColor;
        line-height: 24px;
        text-align: center;
      }

      .inputline-value {
        width: 350px;
        height: 32px;
        box-sizing: border-box;
        border-radius: 0px 0px 0px 0px;
        opacity: 1;
        border: 1px solid #494e57;
        box-sizing: border-box;
        outline: 0;
      }
    }

    .dia-main-addline {
      width: 442px;
      font-size: 16px;
      font-family: PingFang SC-Regular, PingFang SC;
      font-weight: 400;
      color: $textColor;
      line-height: 24px;
      border-bottom: #00faad 1px dashed;
      padding-bottom: 16px;
      margin-bottom: 10px;

      .components-line {
        display: flex;
        // justify-content: space-between;
        align-items: center;
        width: 442px;
        height: 48px;

        .slect-name {
          width: 90px;
          height: 36px;
          font-size: 16px;
          font-family: PingFang SC-Regular, PingFang SC;
          font-weight: 400;
          color: $textColor;
          line-height: 36px;
          text-align: center;
        }

        .selcect-one {
          width: 350px;
          color: #00faad;
          margin-top: 12px;
          height: 36px;
          line-height: 36px;
          background-color: transparent;
          border: #00faad dashed 1px;
          cursor: pointer;

          option {
            background-color: #005c6f !important;
            color: $textColor;
            cursor: pointer;
          }
        }
      }

      .addline-but {
        width: 442px;
        display: flex;
        justify-content: space-around;
        margin-top: 15px;

        .addline-but1 {
          color: #00faad;
          border: 1px solid #00faad;
          cursor: pointer;
          padding: 5px 10px;
        }

        .addline-but1:hover {
          color: $textColor;
        }

        .addline-but2 {
          color: #3581fb;
          border: 1px solid #3581fb;
          cursor: pointer;
          padding: 5px 10px;
        }

        .addline-but2:hover {
          color: $textColor;
        }
      }
    }

    .dia-main-addline:last-of-type {
      padding-bottom: 0;
      margin: 0;
      border: none;
    }

    .showkuang-one {
      position: relative;
      left: 41px;
      width: 400px;
      min-height: 200px;

      .kuangone-main {
        position: absolute;
        width: 100%;
        height: 400px;
      }
    }
  }

  .bottom-bar {
    width: 482px;
    height: 50px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    font-size: 16px;

    .bottom-bar-cancel {
      width: 96px;
      height: 33px;
      border-radius: 5px 5px 5px 5px;
      border: 1px solid #0cb9ae;
      color: #0cb9ae;
      cursor: pointer;
      line-height: 33px;
      text-align: center;
    }

    .bottom-bar-cancel:hover {
      color: #00faad;
    }

    .bottom-bar-confirm {
      width: 96px;
      height: 33px;
      background: #0cb9ae;
      border-radius: 5px 5px 5px 5px;
      cursor: pointer;
      line-height: 33px;
      text-align: center;
    }

    .bottom-bar-confirm:hover {
      color: #10fab4;
    }
  }
}
</style>
